home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / printing / nenscrip.000 / nenscrip / nenscript-1.13++ / fontwidt.c < prev    next >
C/C++ Source or Header  |  1992-11-19  |  2KB  |  101 lines

  1. /*
  2.  *   $Id: fontwidt.c,v 1.2 1992/10/02 01:02:32 craigs Exp $
  3.  *
  4.  *   This code was written by Craig Southeren whilst under contract
  5.  *   to Computer Sciences of Australia, Systems Engineering Division.
  6.  *   It has been kindly released by CSA into the public domain.
  7.  *
  8.  *   Neither CSA or me guarantee that this source code is fit for anything,
  9.  *   so use it at your peril. I don't even work for CSA any more, so
  10.  *   don't bother them about it. If you have any suggestions or comments
  11.  *   (or money, cheques, free trips =8^) !!!!! ) please contact me
  12.  *   care of geoffw@extro.ucc.oz.au
  13.  *
  14.  *   Ugly fix for fractions of points by Jonas Lagerblad (jonas@sisu.se)
  15.  */
  16.  
  17. #include "machdep.h"
  18. #include "defs.h"
  19.  
  20. #include "fontwidt.h"
  21. #include "main.h"
  22.  
  23. /********************************
  24.   globals
  25.  ********************************/
  26.  
  27. /* this table contains the width of a space character for each size of font multiplied by 100
  28.  
  29.   it was produced by the following postscript code
  30.  
  31. %!
  32. /str 10 string def
  33.  
  34. /doit { dup /Courier findfont exch scalefont setfont ( ) stringwidth pop 100 mul cvi str cvs print (, \/* ) print str cvs print ( *\/\n) print } def
  35.  
  36. 5 1 30 { doit } for
  37.  
  38. */
  39.  
  40. static int CourierFontWidths[] = {
  41.  
  42. 299, /* 5 */
  43. 359, /* 6 */
  44. 419, /* 7 */
  45. 479, /* 8 */
  46. 539, /* 9 */
  47. 599, /* 10 */
  48. 659, /* 11 */
  49. 719, /* 12 */
  50. 779, /* 13 */
  51. 839, /* 14 */
  52. 899, /* 15 */
  53. 959, /* 16 */
  54. 1019, /* 17 */
  55. 1079, /* 18 */
  56. 1139, /* 19 */
  57. 1199, /* 20 */
  58. 1259, /* 21 */
  59. 1319, /* 22 */
  60. 1379, /* 23 */
  61. 1439, /* 24 */
  62. 1499, /* 25 */
  63. 1559, /* 26 */
  64. 1619, /* 27 */
  65. 1679, /* 28 */
  66. 1739, /* 29 */
  67. 1799, /* 30 */
  68. };
  69.  
  70.  
  71. /********************************
  72.   function
  73.  ********************************/
  74.  
  75. int GetFontWidth (fontname, size)
  76.  
  77. char *fontname;
  78. long  size;
  79.  
  80. {
  81.   int rem = size % 100;
  82.   size /= 100;
  83.  
  84.   if (strcmp (fontname, "Courier") != 0) {
  85.     fprintf (stderr, "%s: can only use Courier - sorry!!\n", progname);
  86.     exit (1);
  87.   }
  88.  
  89.   if (size < 5 || size > 30 || (size == 30 && rem > 0)) {
  90.     fprintf (stderr, "%s: %i not bwteen valid font sizes of 5 and 30 - sorry!!\n", progname, size);
  91.     exit (1);
  92.   }
  93.   if (rem > 0) {
  94.       /* make an linear approximation of font size */
  95.       return CourierFontWidths [size-5] +
  96.       (CourierFontWidths [size-4] - CourierFontWidths [size-5]) * rem/100;
  97.   } 
  98.  
  99.   return CourierFontWidths [size-5];
  100. }
  101.